package com.snack.system.controller;

import com.snack.common.core.web.controller.BaseController;
import com.snack.common.core.web.domain.AjaxResult;
import com.snack.common.core.web.page.TableDataInfo;
import com.snack.common.log.annotation.Log;
import com.snack.common.log.enums.BusinessType;
import com.snack.common.security.annotation.RequiresPermissions;
import com.snack.system.domain.TsConfig;
import com.snack.system.service.ITsConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 购物设置Controller
 * 
 * @author snack
 * @date 2022-09-18
 */
@RestController
@RequestMapping("/config")
public class TsConfigController extends BaseController
{
    @Autowired
    private ITsConfigService configService;

    /**
     * 查询购物设置列表
     */
    @RequiresPermissions("system:config:list")
    @GetMapping("/list")
    public TableDataInfo list(TsConfig config)
    {
        startPage();
        List<TsConfig> list = configService.selectList(config);
        return getDataTable(list);
    }


    /**
     * 获取购物设置详细信息
     */
    @RequiresPermissions("system:config:query")
    @GetMapping(value = "/{configId}")
    public AjaxResult getInfo(@PathVariable("configId") Long configId)
    {
        return AjaxResult.success(configService.selectById(configId));
    }

    /**
     * 新增购物设置
     */
    @RequiresPermissions("system:config:add")
    @Log(title = "购物设置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TsConfig config)
    {
        return toAjax(configService.insert(config));
    }

    /**
     * 修改购物设置
     */
    @RequiresPermissions("system:config:edit")
    @Log(title = "购物设置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TsConfig config)
    {
        return toAjax(configService.update(config));
    }
}
